#!/usr/bin/env python3
# -*- coding: utf-8 -*-
' main entry '
__author__ = 'pingwu you'

#Flask默认支持的模板是jinja2
from flask import Flask, app, render_template
from flask import request
#默认的jinja2模板路径，基于这个文件的同级目录下的templates文件夹下
#因此如果要调整就基于此进行相对调整，调整到上级目录下的html目录
app = Flask(__name__,template_folder='../html')

@app.route('/abc', methods=['GET', 'POST'])
def abc():
    return render_template("abc/abc.html", message='我传给你的啊', user={"name":"张三"})

@app.route('/', methods=['GET', 'POST'])
def home():
    return '<h1>Home主页啊</h1>'  

@app.route('/signin', methods=['GET'])
def signin_form():
    return '''<form action="/signin" method="post">
              <p><input name="username"></p>
              <p><input name="password" type="password"></p>
              <p><button type="submit">Sign In</button></p>
              </form>'''

@app.route('/signin', methods=['POST'])
def signin():
    # 需要从request对象读取表单内容：
    if request.form['username']=='admin' and request.form['password']=='password':
        return '<h3>Hello, admin!</h3>'
    return '<h3>Bad username or password.</h3>'

def start_flask(name="demo"):    
    app.run(host="0.0.0.0", debug=True, port=9999)
